package main

import (
	"fmt"
	"sync"
)

func main() {
	wg := sync.WaitGroup{}
	wg.Add(10)
	chs := make(chan int, 10)

	//通过一个全局变量控制进channel的顺序
	tag := 1
	for i := 0; i < 10; i++ {
		go func(value int) {
			defer wg.Done()
			for tag == value {
				chs <- tag
			}
		}(i)
	}
	for i := 0; i < 10; i++ {
		fmt.Println(<-chs)
		tag++
	}
	wg.Wait()
}
